
import apis from '../../api/apis.js' 

export default{
	namespaced: true,
	state:{
		halfYear:{},///近半年
		oneMonth:{}, ///近一月
		oneYear:{}, ///近一年
		hour:{},//分时
		Trend:[],///金价走势
		renderdata:{},// 实际渲染的数据
		
		boxtop:{},//最新现金 涨幅 起购数据
		informationDis:{}, ///信息披露
		transactionRule:{},///交易规则 购买与领取
		earningsCost:{},////交易规则 收益与费用
		// id:''   //黄金ID
	},
	mutations:{
		///获取金价走势
		getTrend(state,newData){
			state.Trend=newData
		},
		//获取近半年折现图数据
		getHalfYear(state,newData){
			state.halfYear=newData
		},
		//获取近一年数据
		getOneYear(state,newData){
			state.oneYear=newData
		},
		///获取近一月
		getOneMonth(state,newData){
			state.oneMonth=newData
		},
		//获取分时
		getHour(state,newData){
			state.hour=newData
		},
		//默认值 近一月
		defulat(state,newData){
			state.renderdata=newData
		},
		//点击修改状态
		see(state,value){
			if(value==1){
				state.renderdata=state.hour
			}else if(value==2){
				state.renderdata=state.oneMonth
			}else if(value==3){
				state.renderdata=state.halfYear
			}else{
				state.renderdata=state.oneYear
			}
		},
		// //保存黄金id
		// addId(state,newData){
		// 	state.id=newData
			
		// },
		
		///最新现金 涨幅 起购数据
		boxTOP(state,newData){
			state.boxtop=newData
		},
		////信息披露
		information(state,newData){
			state.informationDis=newData
		},
		///交易规则
		transactionRules(state,newData){
			state.transactionRule=newData
		},
		///交易规则
		earningsCost(state,newData){
			state.earningsCost=newData
		}
	},
	actions:{
		///黄金折线图
		async getGoldChart(context){
			const data =await apis.gold.goldPriceChart()
			// console.log(2222,data.data);
			context.commit('getTrend',data.data.allData)
			context.commit('defulat',data.data.oneMonth)
			context.commit("getOneMonth",data.data.oneMonth)
			context.commit("getHalfYear",data.data.halfYear)
			context.commit("getOneYear",data.data.oneYear)
			context.commit("getHour",data.data.hour)
		},
		
		///黄金页面信息
		async getGoldPage(context){
			const data =await apis.gold.getGoldAccumulate()
			console.log(2222,data.data);
			context.commit('information',data.data.informationDisclosure.basicInformation)
			context.commit('boxTOP',data.data.boxTop)
			//交易规则 购买与领取
			context.commit('transactionRules',data.data.transactionRules.purchaseReceive)
			//交易规则 收益与费用  
			context.commit('earningsCost',data.data.transactionRules.earningsCost)
			// //黄金id
			// console.log(data.data.id);
			// context.commit('addId',data.data.id)
		},
		//黄金支付创建订单
		async addGoldList(context,gold){
			console.log(11111,gold);
			const data =await apis.gold.addGoldList(gold)
			
			return data
		}
	}
}